package in.muton.edushare.pages.cp.courseFBCP;

import in.muton.edushare.pages.common.EdusharePanel;
import in.muton.edushare.wicket.models.CayenneList;

import java.util.HashMap;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;

import com.edushare.common.dao.CourseInstancesDAO;
import com.edushare.common.vo.CourseInstances;
import com.edushare.common.vo.Poll;
import com.edushare.common.vo.Universities;

public class SubListCoursePolls extends EdusharePanel {

	public CayenneList<Poll> pollList = null;
	public IModel<Poll> mainPoll = null;
	public HashMap<IModel<CourseInstances>, Boolean> leftOutCourses;

	public SubListCoursePolls(String id, IModel<Universities> univModel,
			final CourseFeedbackPage page) {
		super(id, univModel, page);
		this.mainPoll = page.getActivePollModel();
		initializePollList();
		add(new Label("pollName", mainPoll.getObject().getPollName()));

		add(new ListView<IModel<Poll>>("pollListLV", pollList.getObject()) {
			@Override
			protected void populateItem(final ListItem<IModel<Poll>> arg0) {
				CourseInstances cinst = new CourseInstancesDAO(
						getORMInterface()).getCourseInstanceById(arg0
						.getModelObject().getObject().getPollGroupId());
				arg0.add(new Label("courseName", cinst.getName()));
				arg0.add(new Link<Void>("resultLink") {
					private static final long serialVersionUID = -3164941615337650648L;

					@Override
					public void onClick() {
					}
				});

				arg0.add(new Link<Void>("reportLink") {
					@Override
					public void onClick() {
					}

					private static final long serialVersionUID = 6750748610408804090L;
				});

				arg0.add(new Link<Void>("settings") {
					private static final long serialVersionUID = 1826330596273217927L;

					@Override
					public void onClick() {
						page.setActivePollModel(arg0.getModelObject());
						page.setParent(false);
						page.setActivePanel(CourseFeedbackPage.SHOW_POLL_SETTINGS);
					}
				});

			}

			private static final long serialVersionUID = -7382467918783403751L;
		});

	}

	private void initializePollList() {
		pollList = new CayenneList<Poll>(null);
		pollList.add(mainPoll);
		pollList.add(mainPoll.getObject().getChildrenPolls());
	}

	private static final long serialVersionUID = -8471569056508752841L;
}
